package me.sdevil507.supports.shiro.helper;

import org.apache.shiro.SecurityUtils;

/**
 * 账户帮助类
 *
 * @author sdevil507
 * created on 2020/2/27
 */
public class ServiceAccountHelper {

    private static String orgIdStr = "orgId";

    private static String userIdStr = "userId";

    /**
     * 获取当前登录用户用户名
     *
     * @return 用户名
     */
    public static String getUsername() {
        return SecurityUtils.getSubject().getPrincipal().toString();
    }

    /**
     * 用户id
     *
     * @param userId 用户id
     */
    public static void setUserId(Long userId) {
        SecurityUtils.getSubject().getSession().setAttribute(ServiceAccountHelper.userIdStr, userId);
    }

    public static Long getUserId() {
        return (Long) SecurityUtils.getSubject().getSession().getAttribute(ServiceAccountHelper.userIdStr);
    }

    /**
     * 设置登录用户所属组织
     *
     * @param orgId 机构id
     */
    public static void setOrgId(Long orgId) {
        SecurityUtils.getSubject().getSession().setAttribute(ServiceAccountHelper.orgIdStr, orgId);
    }

    /**
     * 获取当前用户所属组织
     *
     * @return orgId
     */
    public static Long getOrgId() {
        return (Long) SecurityUtils.getSubject().getSession().getAttribute(ServiceAccountHelper.orgIdStr);
    }

}
